// Learn cc.Class:
//  - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        armatureDisplay:{
            type:dragonBones.ArmatureDisplay,
            default:null
        },
        paoNode:cc.Node
        // foo: {
        //     // ATTRIBUTES:
        //     default: null,        // The default value will be used only when the component attaching
        //                           // to a node for the first time
        //     type: cc.SpriteFrame, // optional, default is typeof default
        //     serializable: true,   // optional, default is true
        // },
        // bar: {
        //     get () {
        //         return this._bar;
        //     },
        //     set (value) {
        //         this._bar = value;
        //     }
        // },
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () {
        //let armatureDisplay=role.getChildByName('animation').getComponent(dragonBones.ArmatureDisplay);
        //     //console.log(armature);
        //     armatureDisplay.armatureName='pao';
        //     armatureDisplay.playAnimation('pao',0)
    },
    left(){
        this.armatureDisplay.armatureName='left';
        this.armatureDisplay.playAnimation('left',0)
    },
    right(){
        this.armatureDisplay.armatureName='right';
        this.armatureDisplay.playAnimation('right',0)
    },
    up(){
        this.armatureDisplay.armatureName='up';
        this.armatureDisplay.playAnimation('up',0)
    },
    down(){
        this.armatureDisplay.armatureName='down';
        this.armatureDisplay.playAnimation('down',0)
    },
    pao(){
        this.paoNode.active=true;
        this.armatureDisplay.armatureName='pao';
        this.armatureDisplay.playAnimation('pao',0)
        this.scheduleOnce(this.die, 5);
    },
    die(){
        this.paoNode.active=false;
        this.armatureDisplay.armatureName='die';
        this.armatureDisplay.playAnimation('die',1);
    },
    stop(){
        this.armatureDisplay.playAnimation(null,0);
        this.armatureDisplay.armature().animation.stop();
    },
    //被拯救
    rescue(){
        this.unscheduleAllCallbacks();
        this.paoNode.active=false;
        this.armatureDisplay.armatureName='down';
    }
    // update (dt) {},
});
